package com.client;

import com.message.resp.ChatResp;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;

/**
 * 接受聊天信息的 handler
 */
@Slf4j
public class ReceiveChatContentHandler extends SimpleChannelInboundHandler<ChatResp> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, ChatResp msg) throws Exception {
        if (msg.getCode() == ChatResp.SEND_SUCCESS) {
            log.info("{}说：{}", msg.getFromUser(), msg.getChatContent());

        } else if (msg.getCode() == ChatResp.RECEIVER_NOT_ONLINE) {
            log.info("{}未上线，发送失败", msg.getReceiverName());

        }

        ctx.fireChannelRead(msg);
    }
}
